home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / D-G / DropInfo ƒ / DI⁄C / DropShell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-11  |  6.0 KB  |  268 lines  |  [TEXT/MPS ]

  1. /******************************************************************************
  2. **
  3. **  Project Name:    DropShell
  4. **     File Name:    DropShell.c
  5. **
  6. **   Description:    Main application code for the QuickShell
  7. **
  8. *******************************************************************************
  9. **                       A U T H O R   I D E N T I T Y
  10. *******************************************************************************
  11. **
  12. **    Initials    Name
  13. **    --------    -----------------------------------------------
  14. **    LDR            Leonard Rosenthol
  15. **    MTC            Marshall Clow
  16. **    SCS            Stephan Somogyi
  17. **
  18. *******************************************************************************
  19. **                      R E V I S I O N   H I S T O R Y
  20. *******************************************************************************
  21. **
  22. **      Date        Time    Author    Description
  23. **    --------    -----    ------    ---------------------------------------------
  24. **    12/09/91            LDR        Added support for new "Select File…" menu item
  25. **                                Quit now sends AEVT to self to be politically correct
  26. **                                Added support for the new gSplashScreen
  27. **    11/24/91            LDR        Added support for the Apple Menu (duh!)
  28. **    10/29/91            SCS        Changes for THINK C 5
  29. **    10/28/91            LDR        Officially renamed DropShell (from QuickShell)
  30. **                                Added a bunch of comments for clarification
  31. **    10/06/91    00:02    MTC        Converted to MPW C
  32. **    04/09/91    00:02    LDR        Added to Projector
  33. **
  34. ******************************************************************************/
  35.  
  36.  
  37. #include "DSGlobals.h"
  38. #include "DSUserProcs.h"
  39. #include "DSAppleEvents.h"
  40.  
  41. #include "DropShell.h"
  42.  
  43. #ifndef THINK_C
  44.     #include <Fonts.h>
  45.     #include <OSEvents.h>
  46.     #include <Resources.h>
  47.     #include <Desk.h>
  48. #endif
  49.  
  50.  
  51. Boolean        gDone, gOApped, gHasAppleEvents, gWasEvent;
  52. EventRecord    gEvent;
  53. MenuHandle    gAppleMenu, gFileMenu;
  54. WindowPtr    gSplashScreen;
  55.  
  56. extern void _DataInit();    
  57.  
  58. /*
  59.     Simple routine installed by InitDialogs for the Resume button in Bomb boxes
  60. */
  61. #pragma segment Main
  62.  
  63. void Panic () {
  64.     ExitToShell ();
  65. }
  66.  
  67.  
  68. #pragma segment Initialize
  69. void InitToolbox (void) 
  70. {
  71.  
  72. #ifndef THINK_C
  73.     UnloadSeg ((Ptr) _DataInit );
  74. #endif
  75.  
  76.     InitGraf ( &qd.thePort );
  77.     InitFonts ();
  78.     InitWindows ();
  79.     InitMenus ();
  80.     TEInit ();
  81.     InitDialogs ((ResumeProcPtr) Panic );
  82.     InitCursor ();
  83.     FlushEvents ( everyEvent, 0 );
  84.     
  85.     // how about some memory fun! Two should be enough!
  86.     MoreMasters ();
  87.     MoreMasters ();
  88.     }
  89.  
  90. /*
  91.     Let's setup those global variables that the DropShell uses.
  92.     
  93.     If you add any globals for your own use,
  94.     init them in the InitUserGlobals routine in DSUserProcs.c
  95. */
  96. #pragma segment Initialize
  97. Boolean InitGlobals (void) 
  98. {
  99.     long aLong;
  100.  
  101.     gDone            = false;
  102.     gOApped            = false;    // probably not since users are supposed to DROP things!
  103.     gHasAppleEvents    = Gestalt ( gestaltAppleEventsAttr, &aLong ) == noErr;
  104.     gSplashScreen    = NULL;
  105.  
  106.     return(InitUserGlobals());    // call the user proc
  107. }
  108.  
  109. /*
  110.     Again, nothing fancy.  Just setting up the menus.
  111.     
  112.     If you add any menus to your DropBox - insert them here!
  113. */
  114. #pragma segment Initialize
  115. void SetUpMenus (void) {
  116.  
  117.     gAppleMenu = GetMenu ( kAppleNum );
  118.     AddResMenu ( gAppleMenu, 'DRVR' );
  119.     InsertMenu ( gAppleMenu, 0 );
  120.  
  121.     gFileMenu = GetMenu ( kFileNum );
  122.     InsertMenu ( gFileMenu, 0 );
  123.     DrawMenuBar ();
  124. }
  125.  
  126. /*
  127.     This routine is called during startup to display a splash screen.
  128.     
  129.     This was recommend by the Blue Team HI person, John Sullivan, who
  130.     feels that all apps should display something so that users can easily
  131.     tell what is running, and be able to switch by clicking.  Thanks John!
  132. */
  133. #pragma segment Initialize
  134. void InstallSplashScreen(void) 
  135. {
  136.     #define windowPicID    128
  137.  
  138.     PicHandle    picH;
  139.  
  140.     if (!gSplashScreen) {  // show the splash screen window
  141.         picH = GetPicture(windowPicID);
  142.         if (picH) {
  143.             gSplashScreen = GetNewWindow(windowPicID, NULL, (WindowPtr)-1L);
  144.             if (gSplashScreen) {
  145.                 SetWindowPic(gSplashScreen, picH);
  146.                 ShowWindow(gSplashScreen);
  147.             }
  148.         }
  149.     }
  150. }
  151.  
  152.  
  153. /*    --------------- Standard Event Handling routines ---------------------- */
  154. #pragma segment Main
  155. void ShowAbout () {
  156.     (void) Alert ( 128, NULL );
  157.     }
  158.  
  159.  
  160. #pragma segment Main
  161. void DoMenu ( long retVal ) {
  162.     short    menuID, itemID;
  163.     Str255    itemStr;
  164.  
  165.     menuID = HiWord ( retVal );
  166.     itemID = LoWord ( retVal );
  167.     
  168.     switch ( menuID ) {
  169.         case kAppleNum:
  170.             if ( itemID == 1 )
  171.                 ShowAbout ();    /*    Show the about box */
  172.             else
  173.             {
  174.                 GetItem(GetMHandle(kAppleNum), itemID, itemStr);
  175.                 OpenDeskAcc(itemStr);
  176.             }
  177.             break;
  178.             
  179.         case kFileNum:
  180.             if ( itemID == 1 )
  181.                 SelectFile();        // call file selection userProc
  182.             else
  183.                 SendQuitToSelf();    // send self a 'quit' event
  184.             break;
  185.         
  186.         default:
  187.             break;
  188.             
  189.         }
  190.     HiliteMenu(0);        // turn it off!
  191.     }
  192.  
  193.  
  194. #pragma segment Main
  195. void DoMouseDown ( EventRecord *curEvent ) {
  196.     WindowPtr    whichWindow;
  197.     short        whichPart;
  198.  
  199.     whichPart = FindWindow ( curEvent->where, &whichWindow );
  200.     switch ( whichPart ) {
  201.         case inMenuBar:
  202.             DoMenu ( MenuSelect ( curEvent->where ));
  203.             break;
  204.         
  205.         case inSysWindow:
  206.             SystemClick ( curEvent, whichWindow );
  207.             break;
  208.         
  209.         case inDrag:
  210.             #ifndef THINK_C
  211.                 DragWindow ( whichWindow, curEvent->where, &qd.screenBits.bounds );
  212.             #else
  213.                 DragWindow ( whichWindow, curEvent->where, &screenBits.bounds );
  214.             #endif
  215.         default:
  216.             break;
  217.         }
  218.     }
  219.  
  220.  
  221. #pragma segment Main
  222. void DoKeyDown ( EventRecord *curEvent ) {
  223.     if ( curEvent->modifiers & cmdKey )
  224.         DoMenu ( MenuKey ((char) curEvent->message & charCodeMask ));
  225.     }
  226.  
  227.  
  228.  
  229. #pragma segment Main
  230. void main ( ) 
  231. {
  232.  
  233.     InitToolbox ();
  234.     if ( InitGlobals () ) {    // if we succeeding in initting self
  235.         if ( !gHasAppleEvents )
  236.             ErrorAlert ( kErrStringID, kCantRunErr, 0 );
  237.         else {
  238.             InitAEVTStuff ();
  239.             SetUpMenus ();
  240.             InstallSplashScreen ();
  241.             
  242.             while ( !gDone ) {
  243.                 gWasEvent = WaitNextEvent ( everyEvent, &gEvent, 0, NULL );
  244.                 if ( gWasEvent ) {
  245.                     switch ( gEvent.what ) {
  246.                         case kHighLevelEvent:
  247.                             DoHighLevelEvent ( &gEvent );
  248.                             break;
  249.                             
  250.                         case mouseDown:
  251.                             DoMouseDown ( &gEvent );
  252.                             break;
  253.                             
  254.                         case keyDown:
  255.                         case autoKey:
  256.                             DoKeyDown ( &gEvent );
  257.                             break;
  258.                             
  259.                         default:
  260.                             break;
  261.                     }
  262.                 }
  263.             }
  264.         }
  265.         DisposeUserGlobals();    // call the userproc to clean itself up
  266.     }
  267. }
  268.